#ifndef FRAMEMODEL_H
#define FRAMEMODEL_H

#include "protocol.h"

#include <QFile>
#include <QVector>

class FrameModel : public ProtocolTableModel
{
    Q_OBJECT
public:
    FrameModel(const QString& fileName, const QByteArray& key, QObject *parent = 0);

signals:
    void openTempFile(const QString fileName);
public slots:

private:
    mutable QFile file;
    mutable int maxColumns;
    QVector<qint64> records;
    qint64 firstPos;
    qint64 searchPos;
    mutable int cacheRow;
    mutable int recordSize;
    mutable QByteArray record;
    QByteArray code;
    void loadRecord(int row) const;
    bool calcRecords(void);
    int maxDisplaySize(void) const;
    void filterSize(const QModelIndex& index);

    // QAbstractItemModel interface
public:
    int rowCount(const QModelIndex &parent) const;
    int columnCount(const QModelIndex &parent) const;
    QVariant data(const QModelIndex &index, int role) const;
    void fetchMore(const QModelIndex &parent);
    bool canFetchMore(const QModelIndex &parent) const;
    QVariant headerData(int section, Qt::Orientation orientation, int role) const;

    // ProtocolTableModel interface
public:
    qint64 position(const QModelIndex &index);
    QModelIndex locate(qint64 pos);
    bool deleteRows(const QString &fileName, const QModelIndexList &rows);
    bool deleteColumns(const QString &fileName, const QModelIndexList &cols);
    bool saveRows(const QString &fileName, const QModelIndexList &rows);
    bool saveColumns(const QString &fileName, const QModelIndexList &cols);
    bool supportFilter(const QModelIndex& index) { Q_UNUSED(index); return true; };
    void filter(const QModelIndex& index);
};

#endif // FRAMEMODEL_H
